package org.csu.mypetstore.web.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.domain.Order;
import org.csu.mypetstore.service.OrderService;

public class ConfirmOrderFormServlet extends HttpServlet {
    private static final String CONFIRM_ORDER_FORM = "/WEB-INF/jsp/account/ConfirmOrder.jsp";
    private static final String SHIPPINGFORM = "/WEB-INF/jsp/order/ShippingForm.jsp";
    private String shippingAddressRequired;
    private Order order;
    private OrderService orderService;

    public ConfirmOrderFormServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.shippingAddressRequired = request.getParameter("shippingAddressRequired");
        this.order = new Order();
        HttpSession session = request.getSession();
        this.order = (Order)session.getAttribute("order");
        Account account = (Account)session.getAttribute("account");
        if (this.shippingAddressRequired == null) {
            request.getRequestDispatcher(CONFIRM_ORDER_FORM).forward(request, response);
        } else {
            this.shippingAddressRequired = null;
            request.getRequestDispatcher(SHIPPINGFORM).forward(request, response);
        }

    }
}
